package com.caiyi.financial.nirvana.sms.scheduled;

import com.caiyi.financial.nirvana.sms.service.SmsMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MsgCountTask {

    private static final Logger logger = LoggerFactory.getLogger(MsgCountTask.class);
    @Autowired
    private SmsMsgService smsMsgService;

    /**
     * 每十分钟更新统计表数据
     */
    @Scheduled(cron = "0 */10 * * * ?")
    public void msgCount() {
        try {
            //更新三天之前的统计数据
            LocalDateTime startDate = LocalDateTime.now();
            int hour = startDate.getHour();
            int minute = startDate.getMinute();
            if (hour == 4 && minute < 10) {
                smsMsgService.threeDaysAgo();
            }
            //更新当天数据
            smsMsgService.smsDayAccount();
        } catch (Exception e) {
            logger.error("MsgCountTask msgCount error", e);
        }
    }

}
